import { ToolTipItem } from "../../../../../com/mui/manager/ToolTipItem";
import { ERuneType } from "../../../../../Message/Public/ERuneType";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { BaseItem } from "../../common/BaseItem";
import { LadderBattlefieldUtil } from "../../ladderBattlefield/LadderBattlefieldUtil";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { Cache } from "../../../cache/Cache";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { RuneExtraConfig } from "../../../resource/RuneExtraConfig";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ItemData } from "../../../resource/info/ItemData";
type int = number;
//class SkillRuneItem
    
    export  class SkillRuneItem extends ToolTipItem
    {
        constructor(arg1: int, arg2: Boolean=false)
        {
            super();
            this._iPos = arg1;
            this._isLocked = arg2;
            this.doubleClickEnabled = true;
            if (arg1 <= 4) 
            {
                this._runeType = ERuneType._ERuneTypeNormal;
            }
            else 
            {
                this._runeType = ERuneType._ERuneTypeSkill;
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._bmpBg = new Object /* flash.display.Bitmap */();
            this.addChild(this._bmpBg);
            if (this._iPos <= 4) 
            {
                this._bmpBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.runeGeneralBoarder);
                this._bmpBg.x = -9;
                this._bmpBg.y = -9;
            }
            else 
            {
                this._bmpBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PackItemBg);
                this._bmpBg.x = -3;
                this._bmpBg.y = -3;
            }
            var loc1=Language.getString(44031);
            if (this._iPos > 4) 
            {
                loc1 = Language.getString(44032);
            }
            var loc2=GlobalStyle.textFormat1;
            loc2.leading = 3;
            loc2.letterSpacing = 2;
            this._runeTextField = ObjCreate.createTextField(loc1, 1, 1, 32, 32, this, loc2);
            this._runeTextField.wordWrap = true;
            this._runeTextField.multiline = true;
            this._lockBitmap = GlobalClass.getBitmap(ImagesConst.LockBig);
            this._lockBitmap.x = 8;
            this._lockBitmap.y = 6;
            this.addChild(this._lockBitmap);
            this._runeItem = new BaseItem();
            this._runeItem.isShowLock = true;
            this._runeItem.width = 32;
            this._runeItem.height = 32;
            this._runeItem.mouseEnabled = true;
            this._runeItem.doubleClickEnabled = true;
            this._runeItem.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onRuneItemDblClick);
            this.addChild(this._runeItem);
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClick);
            this.updateView();
            return;
        }

        /* internal  */onRuneItemDblClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                return;
            }
            if (this._runeItemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.RuneRemove, this._runeItemData.uid));
            }
            return;
        }

        /* internal  */onMouseClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (LadderBattlefieldUtil.isInLadderBattlefield) 
            {
                return;
            }
            if (this._isLocked) 
            {
                if (this._iPos <= 4) 
                {
                    this.checkOpenExtra(ERuneType._ERuneTypeNormal);
                }
                else 
                {
                    this.checkOpenExtra(ERuneType._ERuneTypeSkill);
                }
            }
            else if (this._iPos <= 4 && !this._runeItemData) 
            {
                MsgManager.showRollTipsMsg(Language.getString(44034));
            }
            else if (this._iPos > 4 && !this._runeItemData) 
            {
                MsgManager.showRollTipsMsg(Language.getString(44035));
            }
            return;
        }

        /* internal  */checkOpenExtra(arg1: int): void
        {
            var type: int;
            var tipText: string;
            var onSelect: Function;

            var loc1;
            type = arg1;
            tipText = "";
            if (Cache.instance.rune.runeInfo) 
            {
                onSelect = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.RuneOpenExtra, type));
                    }
                    return;
                }
                if (type != ERuneType._ERuneTypeNormal) 
                {
                    tipText = Language.getStringByParam(44069, RuneExtraConfig.instance.getInfoByTypeAndNum(type, Cache.instance.rune.runeInfo.skillExtraNum).materialNum, Cache.instance.rune.runeInfo.skillExtraNum + 1);
                }
                else 
                {
                    tipText = Language.getStringByParam(44068, RuneExtraConfig.instance.getInfoByTypeAndNum(type, Cache.instance.rune.runeInfo.normalExtraNum).materialNum, Cache.instance.rune.runeInfo.normalExtraNum + 1);
                }
                Alert.show(tipText, null, Alert.OK | Alert.CANCEL, null, onSelect);
            }
            return;
        }

        /* internal  */setToolTipData(): void
        {
            var loc1=null;
            var loc2=null;
            if (this._runeItemData) 
            {
                this.toolTipData = "";
            }
            else 
            {
                if (this._iPos <= 4) 
                {
                    loc1 = Language.getString(44036);
                }
                else 
                {
                    loc1 = Language.getString(44037);
                }
                loc1 = loc1 + "<br><br>";
                if (this._isLocked) 
                {
                    if (Cache.instance.rune.runeInfo) 
                    {
                        if (this._iPos <= 4) 
                        {
                            loc2 = RuneExtraConfig.instance.getInfoByTypeAndNum(ERuneType._ERuneTypeNormal, Cache.instance.rune.runeInfo.normalExtraNum);
                            if (loc2) 
                            {
                                loc1 = loc1 + Language.getStringByParam(44070, Cache.instance.rune.runeInfo.normalExtraNum + 1, loc2.materialNum);
                            }
                        }
                        else 
                        {
                            loc2 = RuneExtraConfig.instance.getInfoByTypeAndNum(ERuneType._ERuneTypeSkill, Cache.instance.rune.runeInfo.skillExtraNum);
                            if (loc2) 
                            {
                                loc1 = loc1 + Language.getStringByParam(44071, Cache.instance.rune.runeInfo.skillExtraNum + 1, loc2.materialNum);
                            }
                        }
                    }
                }
                else 
                {
                    if (this._iPos <= 4) 
                    {
                        loc1 = loc1 + Language.getString(44039);
                    }
                    else 
                    {
                        loc1 = loc1 + Language.getString(44040);
                    }
                    loc1 = loc1 + Language.getString(44041);
                }
                this.toolTipData = loc1;
            }
            return;
        }

        /* internal  */updateView(): void
        {
            if (this._runeItemData) 
            {
                this._runeItem.visible = true;
                this._runeItem.itemData = this._runeItemData;
                this._runeTextField.visible = false;
            }
            else 
            {
                this._runeItem.visible = false;
                this._runeTextField.visible = true;
            }
            this._lockBitmap.visible = this._isLocked;
            if (this._isLocked) 
            {
                this._runeTextField.visible = false;
            }
            this.setToolTipData();
            return;
        }

        public set runeBimtapdata(arg1: Object /* flash.display.BitmapData */)
        {
            if (!arg1) 
            {
                arg1 = new Object /* flash.display.BitmapData */(0, 0);
            }
            this._runeBitmapData = arg1;
            this.updateView();
            return;
        }

        public set selected(arg1: Boolean)
        {
            if (arg1) 
            {
                this.filters = [FilterConst.itemChooseFilter];
            }
            else 
            {
                this.filters = [];
            }
            return;
        }

        public set runeItemData(arg1: ItemData)
        {
            this._runeItemData = arg1;
            this.updateView();
            return;
        }

        public get runeItemData(): ItemData
        {
            return this._runeItemData;
        }

        public get pos(): int
        {
            return this._iPos;
        }

        public set isLocked(arg1: Boolean)
        {
            this._isLocked = arg1;
            this.updateView();
            return;
        }

        public get isLocked(): Boolean
        {
            return this._isLocked;
        }

        public get runeType(): int
        {
            return this._runeType;
        }

        /* internal */ /* var */_iPos: int;

        /* internal */ /* var */_bmpBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRune: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isSelected: Boolean;

        /* internal */ /* var */_runeItemData: ItemData;

        /* internal */ /* var */_runeItem: BaseItem;

        /* internal */ /* var */_lockBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isLocked: Boolean=false;

        /* internal */ /* var */_runeBitmapData: Object /* flash.display.BitmapData */;

        /* internal */ /* var */_runeTextField: Object /* flash.text.TextField */;

        /* internal */ /* var */_runeType: int=1;
    }
